<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.com/license/gpl GPL License
 */
 
class tbdata_ctl_product extends tbdata_controller{

	public function __construct($app){
		parent::__construct($app);
		$this->product_model = $this->app->model('product');
		$this->goods_model = $this->app->model('goods');
	}
    
    function index(){
		$product_id = $this->request['product_id'];
		$product = $this->product_model->getList('*',array('product_id'=>$product_id),0,1);
		$product = $product[0];
		$props_str = explode(';',$product['props_str']);
		foreach($props_str as $s){
			$tmp = explode(':',$s);
			$tmp_props_str[$tmp[0]] = $tmp[1];
		}
		$product['props_str'] = $tmp_props_str;
		$tmp = explode(';',$product['binds_str']);
		foreach($tmp as $v){
			$_tmp = explode(':',$v);
			$binds_str[$_tmp[0]] = $_tmp[1];
		}
		$product['binds_str'] = $binds_str;
		$this->pagedata['product'] = $product;
		$base_url = substr($product['pic_url'],0,strpos($product['pic_url'],'uploaded')+9);
		$product_imgs[] = $product['pic_url'];
		foreach($product['product_imgs']['product_img'] as $product_img){
			$product_imgs[] = $base_url.$product_img['url'];
		}
		$this->pagedata['product_imgs'] = $product_imgs;

		$goods = $this->goods_model->getList('*',array('product_id'=>$product['id']),0,-1);
		foreach($goods as $row){
			$prices[] = $row['price'];
		}
		$price_limit['min'] = min($prices);
		$price_limit['max'] = max($prices);
		$this->pagedata['goods'] = $goods;
		$this->pagedata['price_limit'] = $price_limit;

		$this->output('product.html');
    }
    
}